﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Web;

namespace CoolCode.Web
{
    public static class Config
    {
        public static string DefaultLanguage
        {
            get
            {
                return ConfigurationSettings.AppSettings["DefaultLanguage"] ?? "S";
            }
        }

        public static bool IsDebug
        {
            get
            {
                return (HttpContext.Current != null && HttpContext.Current.IsDebuggingEnabled);
            }
        }


        public static string AppData
        {
            get
            {
                return Utility.GetMapPath("~/App_Data/");
            }
        }

        public static readonly DateTime MinDate = new DateTime(1900, 1, 1);
        public static readonly DateTime MaxDate = new DateTime(2100, 1, 1);

        public static DateTime Markup(this DateTime date)
        {
            if (date < MinDate || date > MaxDate)
                return MinDate;
            return date;
        }

        public static string CompanyName
        {
            get
            {
                return ConfigurationSettings.AppSettings["CompanyName"];
            }
        }

        public static string SystemName
        {
            get
            {
                return ConfigurationSettings.AppSettings["SystemName"];
            }
        }

        public static string SystemShortName
        {
            get
            {
                return ConfigurationSettings.AppSettings["SystemShortName"];
            }
        }

        public static bool Vailidate(this DateTime? value)
        {
            return value.GetValueOrDefault().InRange(MinDate, MaxDate);
        }

        public static string DateFormat
        {
            get
            {
                return ConfigurationSettings.AppSettings["DateFormat"] ?? "yyyy-MM-dd";
            }
        }

        public static string DateTimeFormat
        {
            get
            {
                return DateFormat + " HH:mm:ss";
            }
        }

        public static string UploadPath
        {
            get
            {
                return Utility.GetMapPath(VirtualUploadPath);
            }
        }

        public static string VirtualUploadPath
        {
            get
            {
                string virtualUploadPath = ConfigurationSettings.AppSettings["UploadPath"] ?? "~/Upload/";
                return virtualUploadPath;
            }
        }
    }
}
